
<table margin="0" padding="0" class="calendars">
<tbody>
  <tr>
    <td class="buttons">
      <form method="get" action="calendar.php">
        <input type="hidden" name="m" value="<?php echo $month; ?>">
        <input type="hidden" name="y" value="<?php echo $year-1; ?>">
        <button type="submit">&lt;&lt;</button>
      </form>
      <form method="get" action="calendar.php">
      <?php
        {
          if( $month-1 <= 0 )
          {
            $m = 12;
            $y = $year - 1;
          }
          else
          {
            $m = $month -1;
            $y = $year;
          }
      ?>
        <input type="hidden" name="y" value="<?php echo $y; ?>">
        <input type="hidden" name="m" value="<?php echo $m; ?>">
        <button type="submit">&lt;</button>
      <?php } ?>
      </form>
    </td>
    <?php echo Appointment::getCalendar( $month, $year ); ?>
    <td class="buttons">
      <form method="get" action="calendar.php">
      <?php
        {
          if( $month+1 >= 13 )
          {
            $m = 1;
            $y = $year + 1;
          }
          else
          {
            $m = $month + 1;
            $y = $year;
          }
      ?>
        <input type="hidden" name="y" value="<?php echo $y; ?>">
        <input type="hidden" name="m" value="<?php echo $m; ?>">
        <button type="submit">&gt;</button>
      <?php } ?>
      </form>
      <form method="get" action="calendar.php">
        <input type="hidden" name="m" value="<?php echo $month; ?>">
        <input type="hidden" name="y" value="<?php echo $year+1; ?>">
        <button type="submit">&gt;&gt;</button>
      </form>
    </td>
  </tr>
</tbody>
</table>

<div>
<p class="pagesep" onclick="toggle('new-app')">Nieuwe afspraak</p>

<form id="new-app" method="post" action="calendar.php" <?php  if($_GET['mode']!='edit'){ ?> style="display: none;" <?php } ?>>
  <button type="submit"><img src="images/save.png">Opslaan</button>
<?php
  if( $_GET['mode']=='edit' )
  {
    $app = Appointment::getById( $_GET['id'] );
?>

  <input type="hidden" name="action" value="edit">
  <input type="hidden" name="id" value="<?php echo $app->getId(); ?>">
  <table class="edit" style="width: 100%;" border="1" cellpadding="0" cellspacing="0">
  <tbody>
    <tr>
      <th>Datum</th>
      <td>
        Datum:
        <select name="day">
<?php for( $i=1 ; $i<32 ; $i++ ) { ?>
          <option value="<?php echo $i; ?>"<?php echo ($app->getTimestamp()->getDay()==$i) ? ' selected="yes"' : '';?>><?php echo str_pad( $i, 2, '0', STR_PAD_LEFT); ?></option>
<?php } ?>

        </select>
        /
        <select name="month">
<?php for( $i=1 ; $i<13 ; $i++ ) { ?>
          <option value="<?php echo $i; ?>"<?php echo ($app->getTimestamp()->getMonth()==$i) ? ' selected="yes"' : '';?>><?php echo str_pad( $i, 2, "0", STR_PAD_LEFT); ?></option>
<?php } ?>
        </select>
        /
        <input value="<?php echo $app->getTimestamp()->getYear(); ?>" size="4" name="year" style="width: 60px;" type="text">
        <select name="hour">
<?php for( $i=0 ; $i<24 ; $i++ ) { ?>
          <option value="<?php echo $i; ?>"<?php echo ($app->getTimestamp()->getHour()==$i) ? ' selected="yes"' : '';?>><?php echo str_pad( $i, 2, "0", STR_PAD_LEFT); ?></option>
<?php } ?>
        </select>
        :
        <select name="minutes">
<?php for( $i=0 ; $i<60 ; $i+=5 ) { ?>
          <option value="<?php echo $i; ?>"<?php echo ($app->getTimestamp()->getMinutes()==$i) ? ' selected="yes"' : '';?>><?php echo str_pad( $i, 2, "0", STR_PAD_LEFT); ?></option>
<?php } ?>
        </select>
      </td>
    </tr>
    <tr>
      <th>Onderwerp</th>
      <td><input name="subject" type="text" value="<?php echo $app->getSubject(); ?>"></td>
    </tr>
    <tr>
      <th>Beschrijving</th>
      <td><textarea name="description"><?php echo $app->getDescription(); ?></textarea></td>
    </tr>
  </tbody>
  </table>
<?php } else { ?>
  <input type="hidden" name="action" value="new">
  <table class="edit" style="width: 100%;" border="1" cellpadding="0" cellspacing="0">
  <tbody>
    <tr>
      <th>Datum</th>
      <td>
        Datum:
        <select name="day">
<?php for( $i=1 ; $i<32 ; $i++ ) { ?>
          <option value="<?php echo $i; ?>"<?php echo ($day==$i) ? ' selected="yes"' : '';?>><?php echo str_pad( $i, 2, '0', STR_PAD_LEFT); ?></option>
<?php } ?>

        </select>
        /
        <select name="month">
<?php for( $i=1 ; $i<13 ; $i++ ) { ?>
          <option value="<?php echo $i; ?>"<?php echo ($month==$i) ? ' selected="yes"' : '';?>><?php echo str_pad( $i, 2, "0", STR_PAD_LEFT); ?></option>
<?php } ?>
        </select>
        /
        <input value="<?php echo $year; ?>" size="4" name="year" style="width: 60px;" type="text">
        <select name="hour">
        
<?php for( $i=0 ; $i<24 ; $i++ ) { ?>
          <option value="<?php echo $i; ?>"<?php echo (date('H')==str_pad( $i, 2, '0', STR_PAD_LEFT)) ? ' selected="yes"' : '';?>><?php echo str_pad( $i, 2, '0', STR_PAD_LEFT); ?></option>
<?php } ?>
        </select>
        :
        <select name="minutes">
<?php for( $i=0 ; $i<60 ; $i+=5 ) { ?>
          <option value="<?php echo $i; ?>"<?php echo (intval(date('i'))<$i+5 && intval(date('i'))>=$i) ? ' selected="yes"' : '';?>><?php echo str_pad( $i, 2, "0", STR_PAD_LEFT); ?></option>
<?php } ?>
        </select>
      </td>
    </tr>
    <tr>
      <th>Onderwerp</th>
      <td><input name="subject" type="text"></td>
    </tr>
    <tr>
      <th>Beschrijving</th>
      <td><textarea name="description"></textarea></td>
    </tr>
  </tbody>
  </table>
<?php } ?>
</form>

<p class="pagesep">Afspraken voor <?php echo date( 'j F Y', mktime(0,0,0,$month,$day,$year) ); ?></p>

<table class="edit" style="width: 100%;" border="1" cellpadding="0" cellspacing="0">
<tbody>
  <tr>
    <th width="160">Tijd</th>
    <th>Onderwerp</th>
    <th width="70">Opties</th>
  </tr>
<?php
$apps = Appointment::getByDay($month,$day,$year);
foreach( $apps as &$app ){
?>
  <tr>
    <td>
      <?php
        echo $app->getTimestamp()->show();
      ?>
    </td>
    <td>
      <b><?php echo $app->getSubject() ?></b>
      <div id="<?php echo "t".$app->getId() ?>" style="display: none;">
        <?php echo $app->getDescription() ?>
      </div>
    </td>
    <td class="options">
      <a href="#" title="Meer"><img src="images/expand.png" alt="Meer" onclick="toggle('<?php echo "t".$app->getId() ?>')" border="0"></a>
      <a href="calendar.php?y=<?php echo $year; ?>&m=<?php echo $month; ?>&d=<?php echo $day; ?>&mode=edit&id=<?php echo $app->getId() ?>"><img src="images/edit.png" border="0" alt="Afspraak bewerken"></a>
      <a href="calendar.php?y=<?php echo $year; ?>&m=<?php echo $month; ?>&d=<?php echo $day; ?>&mode=delete&id=<?php echo $app->getId() ?>"><img src="images/remove-small.png" border="0" alt="Verwijder deze afspraak"></a>
    </td>
  </tr>
<?php
}
if( count($apps) < 1 ) { ?>
  <tr>
    <td><br></td>
    <td><i>Er zijn geen afspraken voor vandaag</i></td>
    <td><br></td>
  </tr>
<?php } ?>
</tbody>
</table>

<p class="pagesep">Afspraken binnenkort</p>

<table class="edit" style="width: 100%;" border="1" cellpadding="0" cellspacing="0">
<tbody>
  <tr>
    <th width="160">Tijd</th>
    <th>Onderwerp</th>
    <th width="70">Opties</th>
  </tr>
<?php
$apps = Appointment::getByLimit();
foreach( $apps as &$app ){
?>
  <tr>
    <td>
      <?php
        echo $app->getTimestamp()->show();
      ?>
    </td>
    <td>
      <b><?php echo $app->getSubject() ?></b>
      <div id="<?php echo $app->getId() ?>" style="display: none;">
        <?php echo $app->getDescription() ?>
      </div>
    </td>
    <td class="options">
      <a href="#" onclick="toggle('<?php echo $app->getId() ?>')"><img src="images/expand.png" border="0" alt="Meer"></a>
      <a href="calendar.php?y=<?php echo $year; ?>&m=<?php echo $month; ?>&d=<?php echo $day; ?>&mode=edit&id=<?php echo $app->getId() ?>"><img src="images/edit.png" border="0" alt="Afspraak bewerken"></a>
      <a href="calendar.php?y=<?php echo $year; ?>&m=<?php echo $month; ?>&d=<?php echo $day; ?>&mode=delete&id=<?php echo $app->getId() ?>" onclick="return confirm('Wil je deze afspraak echt verwijderen?')"><img src="images/remove-small.png" border="0" alt="Verwijder deze afspraak"></a>
    </td>
  </tr>
<?php
}
if( count($apps) < 1 ) { ?>
  <tr>
    <td><br></td>
    <td><i>Er zijn geen afspraken voor vandaag</i></td>
    <td><br></td>
  </tr>
<?php } ?>
</tbody>
</table>
